package com.cssl.service.impl;

import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.cssl.config.RabbitMqConfig2;
import com.cssl.domain.DtsAddress;
import com.cssl.domain.DtsCart;
import com.cssl.domain.DtsCoupon;
import com.cssl.domain.Dtsorder;
import com.cssl.domain.dto.*;
import com.cssl.mapper.*;
import com.cssl.service.DtsorderService;
import com.cssl.util.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;

@Service
public class DtsorderServiceImpl implements DtsorderService {
    @Autowired
    private DtsorderMapper mapper;
    @Autowired
    private DtsCartMapper cartMapper;
    @Autowired
    private GroupOnMapper groupOnMapper;
    @Autowired
    private DtsAddressMapper dtsAddressMapper;
    @Autowired
    private DtsGoodsMapper goodsMapper;
    @Autowired
    private StringRedisTemplate template;
    @Autowired
    private DtsCouponMapper couponMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private ThreadPool threadPool;
    private ExecutorService pool;

    @Autowired
    private AlipayPayment payment;

    @PostConstruct
    public void init() {
        pool = threadPool.getPool();
    }

    /**
     * 后台订单详情显示
     */
    @Override
    public Map findPageorder(DtsorderDto dtsorder) {
        Page page = PageHelper.startPage(dtsorder.getPage(), dtsorder.getLimit());
        mapper.findPageorder(dtsorder);
        Map map = new HashMap();
        map.put("list", page.getResult());
        map.put("total", page.getTotal());
        map.put("totalPage", page.getPages());
        map.put("pageNum", page.getPageNum());
        map.put("pageSize", page.getPageSize());
        return map;
    }

    @Override
    public boolean orderdelete(String ids) {
        return mapper.orderdelete(ids);
    }


    //    TODO 将之前的新增评论后,新增对应的oder_goods 中的comment id
    @Transactional
    @Override
    public Result addDirectUserOrder(DirectUserOrder userOrder) {
        //查寻用户地址,名称,手机号
        Integer loginId = 0;
        try {
            loginId = StpKit.USER.getLoginIdAsInt();
        } catch (NotLoginException e) {
            System.out.println("e = " + e);
        }
        //用户信息
        DtsAddress address = dtsAddressMapper.getAddressByUid(loginId);
        Integer res = null;//判断是否添加成功,添加成功,则添加order_goods
        List<String> strings = SubStringUtil.subGoodsSpecifications(userOrder.getSpecifications());//截取规格
        Map<String, Object> map = new HashMap();
        Double price = goodsMapper.getOneGoodsInfo(userOrder.getGoodsId(), strings);
        Double goodsPrice = price * userOrder.getNumber();
        String orderSn = String.valueOf(Instant.now().toEpochMilli());
        LocalDateTime now = LocalDateTime.now();
        // 加上 1 天
        LocalDateTime futureTime = now.plusDays(1);
        map.put("userId", loginId);
        map.put("endTime", futureTime);
        map.put("addTime", now);
        map.put("orderSn", orderSn);
        map.put("userAddress", address); //name,mobile,address
        map.put("goodsPrice", goodsPrice);
        //配送,优惠券,用户积分 减免暂时不做
        res = mapper.addDirectOrder(map);

        if (res != null) {
            //成功
            Map<String, Object> currnetMap = new HashMap();
            Dtsorder dtsorder = mapper.getOrderIdByOrderSn(map.get("orderSn").toString());
            Map goodsMap = mapper.getGoodsMoreInfo(userOrder.getGoodsId(), strings);
            currnetMap.put("orderId", dtsorder.getId());
            currnetMap.put("jsonSpecifications", SubStringUtil.giveStringsBackJson(strings));
            currnetMap.put("goodsInfo", goodsMap);
            currnetMap.put("number", userOrder.getNumber());
            Integer addRes = mapper.addOrderGoods(currnetMap);
            if (addRes != null) {
                //减去对应的库存
                Map finalMap = currnetMap;
                pool.execute(() -> {
                    DtsCart cart = new DtsCart();
                    Map goodsMaps = (Map) finalMap.get("goodsInfo");
                    cart.setProductId(Integer.parseInt(goodsMaps.get("productId").toString()));
                    cart.setNumber(userOrder.getNumber());
                    goodsMapper.minusNumber(Arrays.asList(cart));
                });
                template.opsForValue().set(StorageVariable.ORDERPAYTIME + ":" + finalMap.get("orderId"), finalMap.get("orderId").toString(), 1, TimeUnit.DAYS);
                return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, dtsorder, System.currentTimeMillis());
            }
        }
        return Result.fail(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, System.currentTimeMillis());
    }


    @Transactional
    @Override
    public Result addCarOrder(List<Integer> goodsId) {
        Integer loginId = 0;
        try {
            loginId = StpKit.USER.getLoginIdAsInt();
        } catch (NotLoginException e) {
            System.out.println("e = " + e);
        }
        if (ObjUtil.isEmpty(goodsId)) {
            return Result.fail(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, System.currentTimeMillis());
        }
        //从购物车中拿到商品信息
        List<DtsCart> cartList = cartMapper.getCarGoodsInfo(goodsId, loginId);
        if (ObjUtil.isEmpty(cartList)) {
            return Result.fail(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, System.currentTimeMillis());
        }
        //添加订单
        //遍历拿到商品的总价
        double sum = cartList.stream().mapToDouble(c -> c.getNumber() * c.getPrice()).sum();
        String orderSn = String.valueOf(Instant.now().toEpochMilli());
        DtsAddress address = dtsAddressMapper.getAddressByUid(loginId);
        LocalDateTime now = LocalDateTime.now();
        // 加上 1 天
        LocalDateTime futureTime = now.plusDays(1);
        Map map = new HashMap();
        map.put("sum", sum);
        map.put("orderSn", orderSn);
        map.put("userId", loginId);
        map.put("address", address);
        map.put("endTime", futureTime);
        Integer orderRes = mapper.addCarOrder(map);
        if (orderRes == null || orderRes <= 0) {
            return Result.fail(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, System.currentTimeMillis());
        }
        //添加订单商品
        Dtsorder orderIdByOrderSn = mapper.getOrderIdByOrderSn(orderSn);
        Integer res = mapper.addOrderGoodsByList(cartList, orderIdByOrderSn.getId());
        if (res != null || res > 0) {
            //成功
            template.opsForValue().set(StorageVariable.ORDERPAYTIME + ":" + orderIdByOrderSn.getId(), orderIdByOrderSn.getId().toString(), 1, TimeUnit.DAYS);
            return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, orderIdByOrderSn.getId(), System.currentTimeMillis());
        }
        return Result.fail(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, System.currentTimeMillis());
    }


    @Transactional
    @Override
    public Integer updateOrderStatus(String s) {
        //订单过期
        return mapper.updateOrderSatus(s);
    }

    @Override
    public Result getOrderDetails(OrderInfoDto orderInfoDto) {
        Map<String, Object> goodsMap = new HashMap<>();
        Map<String, Object> returnMap = new HashMap<>();
        Map<String, Double> priceMap = new HashMap<>();

        Double goodsPrice = 0.0;
        Double freightPrice;
        Double grouponPrice = 0.0;
        if (ObjUtil.isEmpty(orderInfoDto.getGroupId()) || orderInfoDto.getGroupId() == 0) {
            //1.不是团购
            //2.判断是否是直购,用number判断
            if (ObjUtil.isEmpty(orderInfoDto.getNumber()) || orderInfoDto.getNumber() != 0) {
                System.out.println(" 直购 ");
                //直购
                goodsMap = mapper.getDirectInfo(orderInfoDto.getGoodsId(), SubStringUtil.subGoodsSpecifications(orderInfoDto.getSpecifications()));
                goodsMap.put("number", orderInfoDto.getNumber());
                List<Map> list = new ArrayList<>();
                list.add(goodsMap);
                returnMap.put("goodsInfo", CarGoodsUtil.merge(list));
                returnMap.put("which", 2);
                goodsPrice = Double.parseDouble(goodsMap.get("price").toString()) * orderInfoDto.getNumber();
                freightPrice = goodsPrice * 0.01;
            } else {
                System.out.println(" 购物车 ");
                List<Map> mapList = goodsMapper.getGoodsBrandByUid(orderInfoDto.getUserId()); //购物车信息
                for (Map res : mapList) {
                    goodsPrice += (Double.parseDouble(res.get("price").toString()) * Double.parseDouble(res.get("number").toString())); //商品总价
                }
                freightPrice = goodsPrice * 0.01;
                Map<Integer, List<Map>> merge = CarGoodsUtil.merge(mapList);
                returnMap.put("goodsInfo", merge);
                returnMap.put("which", 3);
            }
        } else {
            //团购
            if (ObjUtil.isEmpty(orderInfoDto.getGroupOnId()) && orderInfoDto.getGroupOnId() != 0) {
                //参加别人的团购
                System.out.println(" 拼团 ");
                returnMap.put("which", 0);
            } else {
                System.out.println(" 发起团 ");
                returnMap.put("which", 1);
            }

            goodsMap = mapper.getGoodsGroupPrice(orderInfoDto.getGroupId(), SubStringUtil.subGoodsSpecifications(orderInfoDto.getSpecifications()));
            goodsMap.put("number", orderInfoDto.getNumber());
            goodsPrice = (Double.parseDouble(goodsMap.get("price").toString()) * orderInfoDto.getNumber());
            grouponPrice = orderInfoDto.getNumber() * Double.parseDouble(goodsMap.get("discount").toString());
            freightPrice = goodsPrice * 0.01;
            List<Map> list = new ArrayList<>();
            list.add(goodsMap);
            returnMap.put("goodsInfo", CarGoodsUtil.merge(list));
        }

        System.out.println("grouponPrice = " + goodsPrice);
        Double finalGoodsPrice = goodsPrice;
        Callable<Map> task = () -> {
            List<Map> map = couponMapper.getSuitable(finalGoodsPrice, orderInfoDto.getUserId());
            if (map != null && !map.isEmpty()) {
                return map.get(0);
            }
            return null;
        };

        DtsAddress address = dtsAddressMapper.getAddressByUid(orderInfoDto.getUserId()); //用户默认地址
        Integer count = couponMapper.getCouponCount(orderInfoDto.getUserId());

        BigDecimal goodsPrices = new BigDecimal(goodsPrice).setScale(2, RoundingMode.HALF_UP);
        Double goodsResult = goodsPrices.doubleValue();
        priceMap.put("goodsPrice", goodsResult);

        BigDecimal freightPrices = new BigDecimal(freightPrice * 0.01).setScale(2, RoundingMode.HALF_UP);
        Double result = freightPrices.doubleValue();


        priceMap.put("freightPrice", result);
        priceMap.put("grouponPrice", grouponPrice);
        returnMap.put("address", address);
        returnMap.put("count", count);
        returnMap.put("priceMap", priceMap);
        try {
            returnMap.put("coupon", pool.submit(task).get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, returnMap, System.currentTimeMillis());
    }

    @Override
    public Result commonAddOrder(CommonOrderDto dto) {
        Integer login = 0;

        try {
            login = StpKit.USER.getLoginIdAsInt();
        } catch (Exception e) {
            System.out.println("e = " + e);
        }
        Map<String, Object> mqMap = new HashMap<>();
        Map<String, Object> insertMap = new HashMap<String, Object>();
        Integer finalLogin = login;
        //异步获得通用信息
        Future<Integer> future = pool.submit(() -> {
            String orderSn = String.valueOf(Instant.now().toEpochMilli());
            DtsAddress address = dtsAddressMapper.getAddressByAid(finalLogin, dto.getAddressId());
            System.out.println("address. = " + address.toString());
            if (dto.getWhich() == 3) {
                //购物车
                List<DtsCart> list = mapper.getCartCheckedGoods(finalLogin);
                mqMap.put("goodsInfo", list);

                Double sum = list.stream()
                        .mapToDouble(s -> s.getNumber() * s.getPrice())
                        .sum();
                BigDecimal freightPrices = new BigDecimal(sum * 0.01).setScale(2, RoundingMode.HALF_UP);
                Double result = freightPrices.doubleValue();
                insertMap.put("goodsPrice", sum);
                insertMap.put("Delivery", result);//配送费
                insertMap.put("groupOnPrice", 0);//团购优惠
//                insertMap.put("goodsInfo", list);
            } else {
                //直购,团购
                List<DtsCart> notCartGoods = mapper.getNotCartGoods(dto.getGoodsId(), dto.getProductId());
                notCartGoods.get(0).setNumber(dto.getNumber());//团购,直购永远只有一个商品
                Double sum = notCartGoods.stream()
                        .mapToDouble(DtsCart::getPrice)
                        .sum();
                mqMap.put("goodsInfo", notCartGoods);
                BigDecimal freightPrices = new BigDecimal(sum * dto.getNumber() * 0.01).setScale(2, RoundingMode.HALF_UP);
                Double result = freightPrices.doubleValue();
                insertMap.put("groupOnPrice", 0);//团购优惠
                if (dto.getWhich() == 1) {
                    Map<String, Double> doubleList = mapper.getDiscountMoneyById(dto.getGroupId());//这个id是规则id
                    Object discountObj = doubleList.get("discount");
                    Double discount = null;

                    if (discountObj instanceof BigDecimal) {
                        discount = ((BigDecimal) discountObj).doubleValue();
                    } else if (discountObj instanceof Double) {
                        discount = (Double) discountObj;
                    }

                    insertMap.put("groupOnPrice", discount * dto.getNumber());//团购优惠
                } else if (dto.getWhich() == 0) {
                    Map<String, Double> doubleList = mapper.getJoinDiscountMoneyById(dto.getGroupId());//这个id是他人发起的团购id
                    Object discountObj = doubleList.get("discount");
                    Double discount = null;

                    if (discountObj instanceof BigDecimal) {
                        discount = ((BigDecimal) discountObj).doubleValue();
                    } else if (discountObj instanceof Double) {
                        discount = (Double) discountObj;
                    }

                    insertMap.put("groupOnPrice", discount * dto.getNumber());//拼团优惠
                }
                insertMap.put("Delivery", result);//配送费
                System.out.println("sum = " + sum * dto.getNumber());
                insertMap.put("goodsPrice", sum * dto.getNumber());//商品价格
            }
            LocalDateTime now = LocalDateTime.now();
            // 加上 1 天
            LocalDateTime futureTime = now.plusDays(1);
            mqMap.put("loginId", finalLogin);
            insertMap.put("endTIme", futureTime);
            insertMap.put("loginId", finalLogin);
            insertMap.put("orderSn", orderSn);
            insertMap.put("userInfo", address);//name,address,mobil
            return 0;
        });


        //查询优惠券信息
        insertMap.put("couponPrice", 0);
        DtsCoupon coupon = couponMapper.getCoupOnById(dto.getCouponId(), login);
        if (coupon != null) {
            insertMap.put("couponPrice", coupon.getDisCount());
        }
        int status = 103; //判断团购是否满人
        if (dto.getWhich() == 1) {
            System.out.println("发起团购 ");
            //发起团购
            //1 . 判断该用户团购是否存在
            Integer res = groupOnMapper.groupIsExit(dto.getGroupId(), login);
            if (res != null && res > 0) {
                //存在
                return Result.result(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, 0, System.currentTimeMillis());
            }
            //不存在
            status = 103;
        } else if (dto.getWhich() == 0) {
            //参与团购
            System.out.println(" 参与团购 ");
            //1 . 加上改用户是否满足改团购
            Map<String, Integer> enough = mapper.conditionEnough(dto.getGroupId());
            Integer discountMember = enough.get("discountMember");
            Integer count = enough.get("count");
            if (count + 1 == discountMember) {
                //满足条件
                status = 103;
            } else {
                //不满足条件
                status = 203;
            }
        }
        try {
            future.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        System.out.println("insertMap = " + insertMap.get("Delivery"));
        Double delivery = 0.0;
        Double goodsPrice = 0.0;
        if (insertMap.get("Delivery") != null) {
            delivery = Double.parseDouble(insertMap.get("Delivery").toString());
        }
        if (insertMap.get("goodsPrice") != null) {
            goodsPrice = Double.parseDouble(insertMap.get("goodsPrice").toString());
        }
        Map<String, Object> returnMap = new HashMap<>();

        System.out.println("login:" + insertMap.get("loginId"));
        System.out.println("login:" + insertMap.get("endTIme"));
        System.out.println("orderSn:" + insertMap.get("orderSn"));
        System.out.println("userInfo:" + insertMap.get("userInfo").toString());
        System.out.println("userInfo:" + goodsPrice);
        System.out.println("userInfo:" + delivery);
        System.out.println("userInfo:" + status);

        double groupOnPrice = Double.parseDouble(insertMap.get("groupOnPrice").toString());

        System.out.println("userInfo:" + (goodsPrice + delivery - groupOnPrice));
        insertMap.put("groupOnId", dto.getGroupId());
        insertMap.put("orderPrice", goodsPrice + delivery - groupOnPrice);
        insertMap.put("message", dto.getMessage());
        insertMap.put("status", status);
        Integer res = mapper.addCommonOrder(insertMap);


        Dtsorder orderIdByOrderSn = mapper.getOrderIdByOrderSn(insertMap.get("orderSn").toString());

        template.opsForValue().set(StorageVariable.ORDERPAYTIME + ":" + orderIdByOrderSn.getId(), orderIdByOrderSn.getId() + "", 1, TimeUnit.DAYS);
        returnMap.put("order", orderIdByOrderSn);
        mqMap.put("groupId", dto.getGroupId());
        mqMap.put("orderInfo", orderIdByOrderSn);
        mqMap.put("which", dto.getWhich());

        CorrelationData data = new CorrelationData();
        data.setId(orderIdByOrderSn.getId().toString());


        returnMap.put("name", "商品直购");
        if (dto.getWhich() == 3) {
            //发送删除购物车
            mqMap.put("action", 2);
            returnMap.put("name", "购物车");
        }
        if (dto.getWhich() == 1 || dto.getWhich() == 0) {
            //团购
            mqMap.put("action", 3);
            returnMap.put("name", "团购");
        }
        if (res != null && res > 0) {
            String json = "";
            //创建成功,向rabbitmq发送创建订单商品
            try {
                json = objectMapper.writeValueAsString(mqMap);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
            rabbitTemplate.convertAndSend(RabbitMqConfig2.ORDER_GOOD_EXCHANGE, RabbitMqConfig2.ORDER_GOODS_ROUTINGKEY, json, data);
            return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, returnMap, System.currentTimeMillis());
        }
        return Result.result(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, 0, System.currentTimeMillis());
    }

    @RabbitListener(queues = RabbitMqConfig2.ORDER_GOOD_QUEUE)
    public void doAction(String msg, Message message, Channel channel) {
        Map map = JSONObject.parseObject(msg, Map.class);
        addOrderGoods(map);//既然每个新增订单请求都需要新增订单商品,那么直接调用方法不使用消息队列
        Object obj = map.get("action");
        String action = "";
        if (obj != null) {
            action = obj.toString();
        }
        System.out.println("action = " + action);
        try {
            // 处理消息逻辑
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
        if (action.equals("2")) {
            deleteCarGoods(map);
        }
        if (action.equals("3")) {
            addGroupGoods(map);
        }
    }

    //假装多模块监听rabbitmq
    public void deleteCarGoods(Map<String, Object> map) {
        //执行删除购物车选中商品
        Integer loginId = Integer.parseInt(map.get("loginId").toString());
        Integer flag = cartMapper.removeCartGoods(loginId);
        System.out.println("删除商品结果integer = " + flag);
    }

    public void addGroupGoods(Map<String, Object> map) {
        //执行团购商品
        Integer loginId = Integer.parseInt(map.get("loginId").toString());
        Dtsorder orderInfo = JSONObject.parseObject(JSONObject.toJSONString(map.get("orderInfo")), Dtsorder.class);
        Integer groupId = Integer.parseInt(map.get("groupId").toString()); //当是发起团购时这个是规则id
        Integer addGroup = mapper.addGroup(loginId, orderInfo, loginId, groupId, 0);
        System.out.println("新增团购结果integer = " + addGroup);
    }

    public void addOrderGoods(Map<String, Object> map) {
        //执行新增订单商品
        List<DtsCart> cartList = (List<DtsCart>) map.get("goodsInfo");
        Dtsorder orderInfo = JSONObject.parseObject(JSONObject.toJSONString(map.get("orderInfo")), Dtsorder.class);
        Integer integer = mapper.addOrderGoodsByList(cartList, orderInfo.getId());
        System.out.println("新增订单商品结果integer = " + integer);
    }
    @Override
    public Integer updateorder(Map map) {
        return mapper.updateorder(map);
    }


    @Override
    public Result QRCode(Dtsorder dtsorder) {
        Integer oid = dtsorder.getId();
        List<Map<String, Object>> payMap = mapper.getPayInfo(oid);
        List<String> goodsName = payMap.stream().map(s -> s.get("goods_name").toString()).collect(Collectors.toList());
        PaymentParam paymentParam = new PaymentParam();
        paymentParam.setOutTradeNo(dtsorder.getId() + "");
        paymentParam.setTotalAmount(BigDecimal.valueOf(Double.parseDouble(payMap.get(0).get("actual_price").toString())));
        paymentParam.setSubject(goodsName.toArray(new String[0]));
        paymentParam.setReturnUrl("https://localhost:8085/users/test");
        paymentParam.setProductCode("QUICK_WAP_WAY");
        String json="";
        try {
            Map<String,Object> returnMap=new HashMap<>();
            Result result = null;
            try {
                result = payment.payZFB(paymentParam);
            } catch (AlipayApiException e) {
                throw new RuntimeException(e);
            }
            String data = result.getData().toString();
            json=data;
            System.out.println("data = " + data);
            JSONObject jsonObject=JSONObject.parseObject(json);
            //得到alipay_trade_precreate_response数据后再强转JSONObject
            JSONObject jsonobj_two=(JSONObject)jsonObject.get("alipay_trade_precreate_response");
            //再通过jsonobj_two获取到二维码地址
            String qrcode=jsonobj_two.get("qr_code").toString();
            returnMap.put("qrcode",qrcode);
            returnMap.put("outTradeNo",dtsorder.getId());
            return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,returnMap,System.currentTimeMillis());
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
